//
//  SINAStuApproveUserNameViewController.m
//  sinashebao
//
//  Created by  androidlongs on 2018/1/26.
//  Copyright © 2018年  androidlongs. All rights reserved.
//

#import "SINAStuApproveUserNameViewController.h"
#import "SINACircularBeadUtils.h"
#import "SINAStuApproveStudentViewController.h"
#import "SINAUiviewClickLiserner.h"
#import "SINAControllerUtils.h"
#import "SINAStudentTabBarViewController.h"
#import "SINATeacherTabBarViewController.h"

@interface SINAStuApproveUserNameViewController ()
@property(strong,nonatomic) UITextField *userNameTextField;
@end

@implementation SINAStuApproveUserNameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initBackItem];
    SINAUserModel *userModel = [[SINACommonUserHelper share] getUserModel];
    if (userModel!=nil) {
        if ([userModel.identitys integerValue]==1) {
            self.navigationItem.title=@"学生认证";
        } else {
            self.navigationItem.title=@"老师认证";
        }
    } else {
        self.navigationItem.title=@"学生认证";
    }
    
    [self initViewFunction];
}
-(void)initBackItem{
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:0 target:self action:@selector(backFunction)];
    //backItem.title = @"返回";
    backItem.image = [UIImage imageNamed:@"back1"];
    self.navigationItem.leftBarButtonItem = backItem;
}
-(void)backFunction{
    if (self.openType==1) {
        //返回个人中心
        [self.navigationController popViewControllerAnimated:YES];
    } else {
        
        SINAUserModel *userModel = [[SINACommonUserHelper share] getUserModel];
        //用户身份标识  1学生  2教师 -1没有选择身份
        //home页面
        if ([userModel.identitys isEqualToString:@"1"]) {
            SINAStudentTabBarViewController *tabBarViewController = [[SINAStudentTabBarViewController alloc]init];
            [[SINAControllerUtils alloc]restoreRootViewController:tabBarViewController andWithWindow:self.view.window];
        } else {
            SINATeacherTabBarViewController *tabBarViewController = [[SINATeacherTabBarViewController alloc]init];
            [[SINAControllerUtils alloc]restoreRootViewController:tabBarViewController andWithWindow:self.view.window];
        }
    }
}
-(void) initViewFunction{
    UIScrollView *mainScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, mainW, mainH-49)];
    mainScrollView.contentSize=CGSizeMake(mainW, mainH+10);
    [self.view addSubview:mainScrollView];
    [self.view setBackgroundColor:[UIColor colorWithHexString:@"#eeeeee"]];
    
    UIView *itemView1 =[[UIScrollView alloc]initWithFrame:CGRectMake(0, 22, mainW, 48)];
    [itemView1 setBackgroundColor:[UIColor whiteColor]];
    [mainScrollView addSubview:itemView1];
    
    
    
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, CGRectGetHeight(itemView1.frame)/2-10, mainW-30, 21)];
    titleLabel.text=@"姓名";
    [titleLabel setFont:[UIFont systemFontOfSize:16]];
    titleLabel.textColor=[UIColor colorWithHexString:@"#212121"];
    
    [itemView1 addSubview:titleLabel];
    
    UITextField *inputTextField = [[UITextField alloc]initWithFrame:CGRectMake(55, CGRectGetHeight(itemView1.frame)/2-17, mainW-45, 36)];
    
    [inputTextField setFont:[UIFont systemFontOfSize:16]];
    inputTextField.textColor=[UIColor colorWithHexString:@"#878787"];
    inputTextField.placeholder=@"请输入真实姓名";
    self.userNameTextField =inputTextField;
    
    [itemView1 addSubview:inputTextField];
    
    
    UILabel *nextLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, CGRectGetMaxY(itemView1.frame)+48, mainW-30, 42)];
    nextLabel.text=@"下一步";
    nextLabel.textAlignment=NSTextAlignmentCenter;
    [nextLabel setFont:[UIFont systemFontOfSize:20]];
    nextLabel.textColor=[UIColor colorWithHexString:@"#ffffff"];
    [SINACircularBeadUtils makeCircularBead:1 andView:nextLabel andIsSetBackground:YES];
    [mainScrollView addSubview:nextLabel];
    
    WeakSelf;
    [[SINAUiviewClickLiserner alloc]viewClickFunction:nextLabel andWithBlick:^(UIView *view) {
        [weakSelf nextFunction];
    }];
    
}
-(void) nextFunction{
    NSString *studentName = self.userNameTextField.text;
    [self.view endEditing:YES];
    if (studentName==nil||studentName.length<1) {
        
        WISAlertView *alertView =
        [[WISAlertView alloc]initWithTitle:@"提示" message:@"请输入真实姓名" sureBtn:@"确定" cancleBtn:nil];
        [alertView showXLAlertView];
        
        return;
    }
    SINAStuApproveStudentViewController *studentController=[[SINAStuApproveStudentViewController alloc]init];
    studentController.studentName = studentName;
    [self.navigationController pushViewController:studentController animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

@end
